package com.hll.thread;

import com.hll.mail.SendTextMail;
import com.hll.pojo.User;

import javax.mail.MessagingException;
import java.security.GeneralSecurityException;

/**
 * @author: Mr.Hu
 * @create: 2021-03-09 09:52
 */
public class SendMailThread implements Runnable {
  private String mail = "2621365348@qq.com";
  private String code = "ctccnkxefnncebic";
  private User user;

  public SendMailThread(User user) {
    setUser(user);
  }

  public String getMail() {
    return mail;
  }

  public void setMail(String mail) {
    this.mail = mail;
  }

  public String getCode() {
    return code;
  }

  public void setCode(String code) {
    this.code = code;
  }

  public User getUser() {
    return user;
  }

  public void setUser(User user) {
    this.user = user;
  }

  @Override
  public void run() {
    String subject = "欢迎注册本公司产品";
    String content =
        "<p><h2>恭喜注册成功！</h2></p>您的用户名为：<h4>"
            + user.getUserName()
            + "</h4>请妥善保管您的密码，如有问题请及时联系网站客服，再次欢迎您的加入！！";
    try {
      SendTextMail.sendMail(mail, code, user.getMail(), subject, content);
    } catch (MessagingException | GeneralSecurityException e) {
      e.printStackTrace();
    }
  }
}
